<template>
	<view class="container">
		<!-- 顶部导航栏 -->
		<view class="ios-top-nav">
			<view class="status-bar"></view>
			<view class="nav-content">
				<view class="search-box" v-if="isSearching">
					<view class="search-input">
						<image src="/static/icons/search.png" mode="aspectFit" class="search-icon"></image>
						<input 
							type="text" 
							v-model="searchKeyword"
							placeholder="搜索学习笔记、经验分享..."
							@confirm="handleSearch"
							@blur="handleSearchBlur"
						/>
						<image 
							v-if="searchKeyword" 
							src="/static/icons/clear.png" 
							mode="aspectFit" 
							class="clear-icon"
							@tap="clearSearch"
						></image>
					</view>
					<text class="cancel-btn" @tap="cancelSearch">取消</text>
				</view>
				<view class="nav-content" v-else>
					<text class="nav-title">热门</text>
					<view class="nav-actions">
						<view class="action-btn search" @tap="startSearch">
							<image src="/static/icons/search.png" mode="aspectFit"></image>
						</view>
						<view class="action-btn publish" @tap="showPublish">
							<image src="/static/icons/publish.png" mode="aspectFit"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 主要内容区域 -->
		<view class="main-content">
			<!-- 分类标签栏 -->
			<scroll-view scroll-x class="category-bar" :show-scrollbar="false">
				<view 
					v-for="(category, index) in categories" 
					:key="index"
					class="category-item"
					:class="{ active: currentCategory === index }"
					@tap="switchCategory(index)">
					<text>{{category}}</text>
				</view>
			</scroll-view>
			
			<!-- 内容瀑布流 -->
			<view class="content-grid">
				<view class="content-column" v-for="(column, columnIndex) in contentColumns" :key="columnIndex">
					<view 
						class="content-card" 
						v-for="(item, index) in column" 
						:key="index"
						@tap="viewContent(item)">
						<image :src="item.image" mode="aspectFill" class="content-image"></image>
						<view class="content-info">
							<text class="content-title">{{item.title}}</text>
							<view class="content-meta">
								<view class="user-info">
									<image :src="item.userAvatar" mode="aspectFill" class="user-avatar"></image>
									<text class="user-name">{{item.userName}}</text>
								</view>
								<view class="interaction-info">
									<view class="interaction-item">
										<image src="/static/icons/like.png" mode="aspectFit"></image>
										<text>{{item.likes}}</text>
									</view>
									<view class="interaction-item">
										<image src="/static/icons/comment.png" mode="aspectFit"></image>
										<text>{{item.comments}}</text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 发布按钮 -->
		<view class="publish-btn" @tap="showPublish">
			<image src="/static/icons/publish.png" mode="aspectFit"></image>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			isSearching: false,
			searchKeyword: '',
			categories: ['推荐', '学习笔记', '知识分享', '校园生活', '考试经验', '学习技巧'],
			currentCategory: 0,
			contentList: [
				{
					id: 1,
					title: '高等数学学习笔记分享',
					image: '/static/content/math-notes.jpg',
					userName: '数学达人',
					userAvatar: '/static/avatars/user1.png',
					likes: 128,
					comments: 32
				},
				{
					id: 2,
					title: '英语四六级备考经验',
					image: '/static/content/english-prep.jpg',
					userName: '英语老师',
					userAvatar: '/static/avatars/user2.png',
					likes: 256,
					comments: 48
				},
				{
					id: 3,
					title: '大学生活日常记录',
					image: '/static/content/campus-life.jpg',
					userName: '校园生活家',
					userAvatar: '/static/avatars/user3.png',
					likes: 89,
					comments: 15
				},
				{
					id: 4,
					title: '考研复习计划分享',
					image: '/static/content/graduate-prep.jpg',
					userName: '考研学长',
					userAvatar: '/static/avatars/user4.png',
					likes: 342,
					comments: 67
				}
			]
		}
	},
	computed: {
		contentColumns() {
			const columns = [[], []];
			// 如果有搜索关键词，过滤内容
			const filteredList = this.searchKeyword 
				? this.contentList.filter(item => 
					item.title.toLowerCase().includes(this.searchKeyword.toLowerCase()) ||
					item.userName.toLowerCase().includes(this.searchKeyword.toLowerCase())
				)
				: this.contentList;
				
			filteredList.forEach((item, index) => {
				columns[index % 2].push(item);
			});
			return columns;
		}
	},
	methods: {
		startSearch() {
			this.isSearching = true;
			this.searchKeyword = '';
		},
		cancelSearch() {
			this.isSearching = false;
			this.searchKeyword = '';
		},
		handleSearch() {
			// 这里可以添加实际的搜索逻辑
			console.log('搜索关键词：', this.searchKeyword);
		},
		handleSearchBlur() {
			// 输入框失去焦点时的处理
			if (!this.searchKeyword) {
				this.cancelSearch();
			}
		},
		clearSearch() {
			this.searchKeyword = '';
		},
		switchCategory(index) {
			this.currentCategory = index;
			// 这里可以添加切换分类后的数据加载逻辑
		},
		showPublish() {
			uni.showToast({
				title: '发布功能开发中',
				icon: 'none'
			});
		},
		viewContent(item) {
			uni.navigateTo({
				url: `/pages/content-detail/content-detail?id=${item.id}`
			});
		}
	}
}
</script>

<style lang="scss">
.container {
	min-height: 100vh;
	background-color: #F8F8F8;
}

/* 顶部导航栏 */
.ios-top-nav {
	background-color: rgba(255, 255, 255, 0.85);
	backdrop-filter: blur(10px);
	-webkit-backdrop-filter: blur(10px);
	border-bottom: 0.5px solid rgba(60, 60, 67, 0.1);
	position: sticky;
	top: 0;
	z-index: 100;
	
	.status-bar {
		height: var(--status-bar-height, 20px);
	}
	
	.nav-content {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 10px 16px;
		min-height: 44px;
	}
	
	.nav-title {
		font-size: 17px;
		font-weight: 600;
		color: #000;
	}
	
	.nav-actions {
		display: flex;
		
		.action-btn {
			width: 32px;
			height: 32px;
			border-radius: 16px;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-left: 8px;
			background-color: rgba(0, 0, 0, 0.03);
			
			image {
				width: 20px;
				height: 20px;
			}
			
			&:active {
				background-color: rgba(0, 0, 0, 0.05);
			}
		}
	}
}

/* 分类标签栏 */
.category-bar {
	background-color: #FFFFFF;
	padding: 12px 16px;
	white-space: nowrap;
	
	.category-item {
		display: inline-block;
		padding: 6px 16px;
		margin-right: 12px;
		border-radius: 16px;
		font-size: 14px;
		color: #666;
		background-color: #F5F5F5;
		
		&.active {
			color: #FFFFFF;
			background-color: #007AFF;
		}
		
		&:last-child {
			margin-right: 0;
		}
	}
}

/* 内容网格 */
.content-grid {
	display: flex;
	padding: 8px;
	
	.content-column {
		flex: 1;
		padding: 0 4px;
		
		.content-card {
			margin-bottom: 12px;
			background-color: #FFFFFF;
			border-radius: 12px;
			overflow: hidden;
			box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
			
			.content-image {
				width: 100%;
				height: 200px;
			}
			
			.content-info {
				padding: 12px;
				
				.content-title {
					font-size: 14px;
					font-weight: 500;
					color: #333;
					margin-bottom: 8px;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					overflow: hidden;
				}
				
				.content-meta {
					display: flex;
					justify-content: space-between;
					align-items: center;
					
					.user-info {
						display: flex;
						align-items: center;
						
						.user-avatar {
							width: 24px;
							height: 24px;
							border-radius: 12px;
							margin-right: 6px;
						}
						
						.user-name {
							font-size: 12px;
							color: #666;
						}
					}
					
					.interaction-info {
						display: flex;
						
						.interaction-item {
							display: flex;
							align-items: center;
							margin-left: 12px;
							
							image {
								width: 14px;
								height: 14px;
								margin-right: 4px;
							}
							
							text {
								font-size: 12px;
								color: #999;
							}
						}
					}
				}
			}
		}
	}
}

/* 发布按钮 */
.publish-btn {
	position: fixed;
	right: 16px;
	bottom: calc(50px + env(safe-area-inset-bottom, 0px) + 16px);
	width: 56px;
	height: 56px;
	background: linear-gradient(135deg, #4268CA 0%, #6B8BEC 100%);
	border-radius: 28px;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 4px 12px rgba(85, 130, 230, 0.3);
	z-index: 100;
	
	image {
		width: 24px;
		height: 24px;
	}
	
	&:active {
		transform: scale(0.95);
		box-shadow: 0 2px 8px rgba(85, 130, 230, 0.2);
	}
}

/* 搜索框样式 */
.search-box {
	display: flex;
	align-items: center;
	width: 100%;
	padding: 0 8px;
	
	.search-input {
		flex: 1;
		height: 32px;
		background-color: rgba(0, 0, 0, 0.03);
		border-radius: 16px;
		display: flex;
		align-items: center;
		padding: 0 12px;
		margin-right: 12px;
		
		.search-icon {
			width: 20px;
			height: 20px;
			margin-right: 8px;
			opacity: 0.6;
		}
		
		input {
			flex: 1;
			height: 32px;
			line-height: 32px;
			font-size: 14px;
			color: #333;
			padding: 0;
			margin: 0;
			background: transparent;
			
			&::placeholder {
				color: rgba(51, 51, 51, 0.35);
				line-height: 32px;
			}
		}
		
		.clear-icon {
			width: 20px;
			height: 20px;
			opacity: 0.6;
		}
	}
	
	.cancel-btn {
		font-size: 14px;
		color: #007AFF;
		padding: 0 4px;
	}
}
</style> 